# 把第二批次需要的文件名写入b2.txt，一共1998个
import csv
import os

directory_path = 'E:/data/palm_vein/SCUT-PV-V2/Ori'  # 替换为你要检查的目录路径

file_lst = []
for file in os.listdir(directory_path):
    file_lst.append(file)

hand_ids = set()
for file in file_lst:
    hand_ids.add(file.split('_')[0])

for hand_id in hand_ids:
    for i in range(9):
        assert f'{hand_id}_{i + 1}.jpg' in file_lst, f"File {hand_id}_{i}.jpg is missing"

csv_file_path = 'b2.txt'
file_lst.sort()
# 使用'w'模式打开文件进行写入，newline=''避免空行

with open('b1.txt', 'r') as f:
    b1_file_lst = f.readlines()
b1_file_set = set()
for file in b1_file_lst:
    b1_file_set.add(file.replace('\n', ''))

with open(csv_file_path, 'w', newline='') as csvfile:
    writer = csv.writer(csvfile)

    for item in file_lst:
        if item not in b1_file_set:
            writer.writerow([item])  # 将每个元素作为列表写入，这样每个元素会单独占一行
